package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by mauricio on 10/1/14.
 */
public class User {
    private String name;
    private String libraryNumber;



    private String password;
    private String email;
    private String phone;
    public static ArrayList<User> resource = new ArrayList<User>();
    private  int id;

    public User(String name, String libraryNumber, String password, String email, String phone) {
        setName(name);
        setEmail(email);
        setPhone(phone);
        setLibraryNumber(libraryNumber);
        setPassword(password);

        this.id = resource.size();
    }
    public User() {
        this.id = resource.size();
    }

    public int getId() {
        return this.id;
    }
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLibraryNumber() {
        return libraryNumber;
    }

    public void setLibraryNumber(String libraryNumber) {
        this.libraryNumber = libraryNumber;
    }

    public static ArrayList<User> getAll() {
        if(resource.size() == 0) {
            resource.add(new User("Mauricio Melo", "999-0001", "p4ssw0rd", "example@example.com", "99 9999 9999"));
            resource.add(new User("Mikaela Melo", "999-0002", "p4ssw0rd2","example@example.com", "99 9999 9999"));
        }

        return resource;
    }


    public static User getByLibraryNumber(String libraryNumber) {

        for (User user : User.getAll()) {
            if (user.getLibraryNumber().equals(libraryNumber)) {
                return user;
            }
        }

        return null;
    }
}
